package com.zhijiang.hospital.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhijiang.hospital.entity.dto.FinIpbItemlistDto;
import com.zhijiang.hospital.entity.dto.OrderDto;
import com.zhijiang.hospital.entity.vo.FinIpbItemlistVo;
import com.zhijiang.hospital.mapper.FinIpbItemlistDtoMapper;
import com.zhijiang.hospital.mapper.OrderDtoMapper;
import com.zhijiang.hospital.service.FinIpbItemlistDtoService;
import com.zhijiang.util.BaseQuery;
import com.zhijiang.util.NumberUtils;
import com.zhijiang.util.PageList;
import com.zhijiang.util.TimeUtil;
import com.zhijiang.util.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2023-02-14 19:24:54
 */
@Service
@Slf4j
public class FinIpbItemlistDtoServiceImpl implements FinIpbItemlistDtoService {
    private static final String PrimaryCareOne = "Ⅰ级护理";
    private static final String PrimaryCareTwo = "Ⅱ级护理";
    private static final String PrimaryCareThree = "Ⅲ级护理";
    @Autowired
    FinIpbItemlistDtoMapper finIpbItemlistDtoMapper;
    @Autowired
    OrderDtoMapper orderDtoMapper;
    @Autowired
    RedisService redisService;

    @Override
    public List<FinIpbItemlistDto> findFinIpbItemlistDto(String startTime, String endTime) {
        List<FinIpbItemlistDto> finIpbItemlistDtos = finIpbItemlistDtoMapper.findFinIpbItemlistDto(startTime, endTime);
        Map<String, List<FinIpbItemlistDto>> collect = finIpbItemlistDtos.stream().collect(Collectors.groupingBy(
                FinIpbItemlistDto::getDeptCode
        ));
        for (FinIpbItemlistDto finIpbItemlistDto : finIpbItemlistDtos) {
            String deptCode = finIpbItemlistDto.getDeptCode();
            List<FinIpbItemlistDto> list = collect.get(deptCode);
            Set<String> strings = collect.keySet();
            for (String string : strings) {
                if (string == deptCode) {
                    List<FinIpbItemlistDto> primaryCareOneList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareOne)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareTwoList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareTwo)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareThreeList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareThree)).collect(Collectors.toList());
                    finIpbItemlistDto.setPrimaryCareOne(primaryCareOneList.size());
                    finIpbItemlistDto.setPrimaryCareTwo(primaryCareTwoList.size());
                    finIpbItemlistDto.setPrimaryCareThree(primaryCareThreeList.size());
                }
            }
        }
        List<FinIpbItemlistDto> collects = finIpbItemlistDtos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
                Comparator.comparing(FinIpbItemlistDto::getDeptCode)
        )), ArrayList::new));
        List<OrderDto> orderDtos = orderDtoMapper.findOrderDto(startTime, endTime);
        List<FinIpbItemlistDto> result = collects.stream().map(m -> {
            orderDtos.stream().filter(m2 -> Objects.equals(m.getDeptCode(), m2.getDeptCode())).forEach(m2 -> {
                m.setExecuteOrderNum(m2.getExecuteOrderNum());
            });
            return m;
        }).collect(Collectors.toList());
        return result;

    }

    @Override
    public Map<String, Object> findFinIpbItemlistDtos(BaseQuery baseQuery) {
        List<FinIpbItemlistDto> list = finIpbItemlistDtoMapper.loadFinIpbItemlistOne(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareOne);
        List<FinIpbItemlistDto> list1 = finIpbItemlistDtoMapper.loadFinIpbItemlistTwo(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareTwo);
        List<FinIpbItemlistDto> list2 = finIpbItemlistDtoMapper.loadFinIpbItemlistThree(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareThree);
        List<FinIpbItemlistDto> finIpbItemlistDtos = finIpbItemlistDtoMapper.findFinIpbItemlistDto(baseQuery.getStartTime(), baseQuery.getEndTime());
        List<FinIpbItemlistDto> collect = finIpbItemlistDtos.stream().distinct().collect(Collectors.toList());
        for (FinIpbItemlistDto finIpbItemlistDto : list) {
            for (FinIpbItemlistDto ipbItemlistDto : collect) {
                if (finIpbItemlistDto.getDeptName().equals(ipbItemlistDto.getDeptName())) {
                    ipbItemlistDto.setPrimaryCareOne(finIpbItemlistDto.getPrimaryCareOne());
                }
            }
        }
        for (FinIpbItemlistDto finIpbItemlistDto : list1) {
            for (FinIpbItemlistDto ipbItemlistDto : collect) {
                if (finIpbItemlistDto.getDeptName().equals(ipbItemlistDto.getDeptName())) {
                    ipbItemlistDto.setPrimaryCareTwo(finIpbItemlistDto.getPrimaryCareTwo());
                }
            }
        }
        for (FinIpbItemlistDto finIpbItemlistDto : list2) {
            for (FinIpbItemlistDto ipbItemlistDto : collect) {
                if (finIpbItemlistDto.getDeptName().equals(ipbItemlistDto.getDeptName())) {
                    ipbItemlistDto.setPrimaryCareThree(finIpbItemlistDto.getPrimaryCareThree());
                }
            }
        }
        FinIpbItemlistDto finIpbItemlistDto = new FinIpbItemlistDto();
        //List<String> executeOrderNum = collect.stream().map(FinIpbItemlistDto::getExecuteOrderNum).collect(Collectors.toList());
        //int sum = executeOrderNum.stream().mapToInt(Integer::parseInt).sum();
        //if (StrUtil.isNotEmpty(String.valueOf(sum)) ){
        //    finIpbItemlistDto.set
        //}
        List<FinIpbItemlistDto> collect1 = collect.stream().filter(finIpbItemlistDto1 -> finIpbItemlistDto1.getPrimaryCareOne() != null).collect(Collectors.toList());
        List<Integer> primaryCareOne = collect1.stream().map(FinIpbItemlistDto::getPrimaryCareOne).collect(Collectors.toList());
        Integer primaryCareOneSum = primaryCareOne.stream().reduce(Integer::sum).orElse(0);
        if (StrUtil.isNotEmpty(String.valueOf(primaryCareOneSum))) {
            finIpbItemlistDto.setPrimaryCareOne(primaryCareOneSum);
        }
        List<FinIpbItemlistDto> collect2 = collect.stream().filter(finIpbItemlistDto1 -> finIpbItemlistDto1.getPrimaryCareTwo() != null).collect(Collectors.toList());
        List<Integer> primaryCareTwo = collect2.stream().map(FinIpbItemlistDto::getPrimaryCareTwo).collect(Collectors.toList());
        Integer primaryCareTwoSum = primaryCareTwo.stream().reduce(Integer::sum).orElse(0);
        if (StrUtil.isNotEmpty(String.valueOf(primaryCareTwoSum))) {
            finIpbItemlistDto.setPrimaryCareTwo(primaryCareTwoSum);
        }
        List<FinIpbItemlistDto> collect3 = collect.stream().filter(finIpbItemlistDto1 -> finIpbItemlistDto1.getPrimaryCareThree() != null).collect(Collectors.toList());
        List<Integer> primaryCareThree = collect3.stream().map(FinIpbItemlistDto::getPrimaryCareThree).collect(Collectors.toList());
        Integer primaryCareThreeSum = primaryCareThree.stream().reduce(Integer::sum).orElse(0);
        if (StrUtil.isNotEmpty(String.valueOf(primaryCareThreeSum))) {
            finIpbItemlistDto.setPrimaryCareThree(primaryCareThreeSum);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("heji", finIpbItemlistDto);
        return map;
    }

    @Override
    public List<FinIpbItemlistDto> loadYearData() {
        DateTime dateTime = DateUtil.beginOfYear(new Date());
        String year = String.valueOf(DateUtil.year(dateTime));
        DateTime dateTime1 = DateUtil.endOfYear(new Date());
        String startTime = Convert.toStr(dateTime);
        String endTime = Convert.toStr(dateTime1);
        if (redisService.hasKey(year + "LoadYearDataFinIpbItemlistDto")) {
            return redisService.getKeyObjectValue(year + "LoadYearDataFinIpbItemlistDto", List.class);
        }
        List<FinIpbItemlistDto> finIpbItemlistDtos = finIpbItemlistDtoMapper.findFinIpbItemlistDto(startTime, endTime);
        Map<String, List<FinIpbItemlistDto>> collect = finIpbItemlistDtos.stream().collect(Collectors.groupingBy(
                FinIpbItemlistDto::getDeptCode
        ));
        for (FinIpbItemlistDto finIpbItemlistDto : finIpbItemlistDtos) {
            String deptCode = finIpbItemlistDto.getDeptCode();
            List<FinIpbItemlistDto> list = collect.get(deptCode);
            Set<String> strings = collect.keySet();
            for (String string : strings) {
                if (string == deptCode) {
                    List<FinIpbItemlistDto> primaryCareOneList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareOne)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareTwoList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareTwo)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareThreeList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareThree)).collect(Collectors.toList());
                    finIpbItemlistDto.setPrimaryCareOne(primaryCareOneList.size());
                    finIpbItemlistDto.setPrimaryCareTwo(primaryCareTwoList.size());
                    finIpbItemlistDto.setPrimaryCareThree(primaryCareThreeList.size());
                }
            }
        }
        List<FinIpbItemlistDto> collects = finIpbItemlistDtos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
                Comparator.comparing(FinIpbItemlistDto::getDeptCode)
        )), ArrayList::new));
        List<OrderDto> orderDtos = orderDtoMapper.findOrderDto(startTime, endTime);
        List<FinIpbItemlistDto> result = collects.stream().map(m -> {
            orderDtos.stream().filter(m2 -> Objects.equals(m.getDeptCode(), m2.getDeptCode())).forEach(m2 -> {
                m.setExecuteOrderNum(m2.getExecuteOrderNum());
            });
            return m;
        }).collect(Collectors.toList());
        redisService.setStringKeyAndValue(year + "LoadYearDataFinIpbItemlistDto", result, 60);
        return result;
    }

    @Override
    public List<FinIpbItemlistDto> loadLastYearData() {

        Date nextYearPreDay = TimeUtil.getNextYearPreDay();
        DateTime dateTime3 = DateUtil.beginOfYear(nextYearPreDay);
        String lastYear = String.valueOf(DateUtil.year(dateTime3));
        DateTime dateTime4 = DateUtil.endOfYear(nextYearPreDay);
        String format = TimeUtil.format(dateTime3);
        String format1 = TimeUtil.format(dateTime4);
        if (redisService.hasKey(lastYear + "loadLastYearDataFinIpbItemlistDto")) {
            return redisService.getKeyObjectValue(lastYear + "loadLastYearDataFinIpbItemlistDto", List.class);
        }

        List<FinIpbItemlistDto> finIpbItemlistDtos = finIpbItemlistDtoMapper.findFinIpbItemlistDto(format, format1);
        Map<String, List<FinIpbItemlistDto>> collect = finIpbItemlistDtos.stream().collect(Collectors.groupingBy(
                FinIpbItemlistDto::getDeptCode
        ));
        for (FinIpbItemlistDto finIpbItemlistDto : finIpbItemlistDtos) {
            String deptCode = finIpbItemlistDto.getDeptCode();
            List<FinIpbItemlistDto> list = collect.get(deptCode);
            Set<String> strings = collect.keySet();
            for (String string : strings) {
                if (string == deptCode) {
                    List<FinIpbItemlistDto> primaryCareOneList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareOne)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareTwoList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareTwo)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareThreeList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareThree)).collect(Collectors.toList());
                    finIpbItemlistDto.setPrimaryCareOne(primaryCareOneList.size());
                    finIpbItemlistDto.setPrimaryCareTwo(primaryCareTwoList.size());
                    finIpbItemlistDto.setPrimaryCareThree(primaryCareThreeList.size());
                }
            }
        }
        List<FinIpbItemlistDto> collects = finIpbItemlistDtos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
                Comparator.comparing(FinIpbItemlistDto::getDeptCode)
        )), ArrayList::new));
        List<OrderDto> orderDtos = orderDtoMapper.findOrderDto(format, format1);
        List<FinIpbItemlistDto> result = collects.stream().map(m -> {
            orderDtos.stream().filter(m2 -> Objects.equals(m.getDeptCode(), m2.getDeptCode())).forEach(m2 -> {
                m.setExecuteOrderNum(m2.getExecuteOrderNum());
            });
            return m;
        }).collect(Collectors.toList());
        redisService.setStringKeyAndValue(lastYear + "loadLastYearDataFinIpbItemlistDto", result, 60);
        return result;
    }

    @Override
    public Object loadChart(String startTime, String endTime) {
        List<FinIpbItemlistDto> finIpbItemlistDtos = finIpbItemlistDtoMapper.findFinIpbItemlistDto(startTime, endTime);
        Map<String, List<FinIpbItemlistDto>> collect = finIpbItemlistDtos.stream().collect(Collectors.groupingBy(
                FinIpbItemlistDto::getDeptCode
        ));
        for (FinIpbItemlistDto finIpbItemlistDto : finIpbItemlistDtos) {
            String deptCode = finIpbItemlistDto.getDeptCode();
            List<FinIpbItemlistDto> list = collect.get(deptCode);
            Set<String> strings = collect.keySet();
            for (String string : strings) {
                if (string == deptCode) {
                    List<FinIpbItemlistDto> primaryCareOneList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareOne)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareTwoList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareTwo)).collect(Collectors.toList());
                    List<FinIpbItemlistDto> primaryCareThreeList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareThree)).collect(Collectors.toList());
                    finIpbItemlistDto.setPrimaryCareOne(primaryCareOneList.size());
                    finIpbItemlistDto.setPrimaryCareTwo(primaryCareTwoList.size());
                    finIpbItemlistDto.setPrimaryCareThree(primaryCareThreeList.size());
                }
            }
        }
        List<FinIpbItemlistDto> collects = finIpbItemlistDtos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
                Comparator.comparing(FinIpbItemlistDto::getDeptCode)
        )), ArrayList::new));
        List<OrderDto> orderDtos = orderDtoMapper.findOrderDto(startTime, endTime);
        List<FinIpbItemlistDto> result = collects.stream().map(m -> {
            orderDtos.stream().filter(m2 -> Objects.equals(m.getDeptCode(), m2.getDeptCode())).forEach(m2 -> {
                m.setExecuteOrderNum(m2.getExecuteOrderNum());
            });
            return m;
        }).collect(Collectors.toList());
        Map<String, List> map = new HashMap<>();
        List<String> nameList = new ArrayList<>();
        List<String> executeOrderNumList = new ArrayList<>();
        List<Integer> primaryCareOneList = new ArrayList<>();
        List<Integer> primaryCareTwoList = new ArrayList<>();
        List<Integer> primaryCareThreeList = new ArrayList<>();
        for (int i = 0; i < result.size(); i++) {
            nameList.add(result.get(i).getDeptName());
            executeOrderNumList.add(result.get(i).getExecuteOrderNum());
            primaryCareOneList.add(result.get(i).getPrimaryCareOne());
            primaryCareTwoList.add(result.get(i).getPrimaryCareTwo());
            primaryCareThreeList.add(result.get(i).getPrimaryCareThree());
        }
        map.put("nameList", nameList);
        map.put("executeOrderNumList", executeOrderNumList);
        map.put("primaryCareOneList", primaryCareOneList);
        map.put("primaryCareTwoList", primaryCareTwoList);
        map.put("primaryCareThreeList", primaryCareThreeList);
        return map;
    }

    @Override
    public PageList<FinIpbItemlistDto> findFinIpbItemlistDtosByPageList(BaseQuery baseQuery) {
        List<FinIpbItemlistDto> list = finIpbItemlistDtoMapper.loadFinIpbItemlistOne(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareOne);
        List<FinIpbItemlistDto> list1 = finIpbItemlistDtoMapper.loadFinIpbItemlistTwo(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareTwo);
        List<FinIpbItemlistDto> list2 = finIpbItemlistDtoMapper.loadFinIpbItemlistThree(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareThree);
        List<FinIpbItemlistDto> finIpbItemlistDtos = finIpbItemlistDtoMapper.findFinIpbItemlistDto(baseQuery.getStartTime(), baseQuery.getEndTime());
        List<FinIpbItemlistDto> collect = finIpbItemlistDtos.stream().distinct().collect(Collectors.toList());
        for (FinIpbItemlistDto finIpbItemlistDto : list) {
            for (FinIpbItemlistDto ipbItemlistDto : collect) {
                if (finIpbItemlistDto.getDeptName().equals(ipbItemlistDto.getDeptName())) {
                    ipbItemlistDto.setPrimaryCareOne(finIpbItemlistDto.getPrimaryCareOne());
                }
            }
        }
        for (FinIpbItemlistDto finIpbItemlistDto : list1) {
            for (FinIpbItemlistDto ipbItemlistDto : collect) {
                if (finIpbItemlistDto.getDeptName().equals(ipbItemlistDto.getDeptName())) {
                    ipbItemlistDto.setPrimaryCareTwo(finIpbItemlistDto.getPrimaryCareTwo());
                }
            }
        }
        for (FinIpbItemlistDto finIpbItemlistDto : list2) {
            for (FinIpbItemlistDto ipbItemlistDto : collect) {
                if (finIpbItemlistDto.getDeptName().equals(ipbItemlistDto.getDeptName())) {
                    ipbItemlistDto.setPrimaryCareThree(finIpbItemlistDto.getPrimaryCareThree());
                }
            }
        }
        List<FinIpbItemlistDto> collect1 = collect.stream().skip((baseQuery.getPage() - 1) * baseQuery.getPageSize()).limit(baseQuery.getPageSize()).collect(Collectors.toList());
        PageList<FinIpbItemlistDto> pageList = new PageList<>();
        pageList.setList(collect1);
        pageList.setPageSize(baseQuery.getPageSize());
        pageList.setTotal(Long.valueOf(String.valueOf(collect.size())));
        pageList.setPage(baseQuery.getPage());
        pageList.setPages(NumberUtils.totalPages(Long.valueOf(String.valueOf(list.size())), baseQuery.getPageSize()));
        return pageList;
    }

    public PageList<FinIpbItemlistDto> getFinIpbItemlistOne(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getPage(), baseQuery.getPageSize());
        List<FinIpbItemlistDto> list = finIpbItemlistDtoMapper.loadFinIpbItemlistOne(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareOne);
        PageInfo<FinIpbItemlistDto> pageInfo = new PageInfo<>(list);
        Integer pageSize = NumberUtils.drawSurplus(pageInfo.getTotal(), baseQuery.getPageSize());
        Integer pages = NumberUtils.totalPages(pageInfo.getTotal(), baseQuery.getPageSize());
        PageList<FinIpbItemlistDto> aisOperRegDtoPageList = new PageList<>(pageInfo.getTotal(), pageInfo.getList(), baseQuery.getPage(), pageSize, pages);
        return aisOperRegDtoPageList;
    }

    public PageList<FinIpbItemlistDto> getFinIpbItemlistTwo(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getPage(), baseQuery.getPageSize());
        List<FinIpbItemlistDto> list1 = finIpbItemlistDtoMapper.loadFinIpbItemlistTwo(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareTwo);
        PageInfo<FinIpbItemlistDto> pageInfo = new PageInfo<>(list1);
        Integer pageSize = NumberUtils.drawSurplus(pageInfo.getTotal(), baseQuery.getPageSize());
        Integer pages = NumberUtils.totalPages(pageInfo.getTotal(), baseQuery.getPageSize());
        PageList<FinIpbItemlistDto> aisOperRegDtoPageList = new PageList<>(pageInfo.getTotal(), pageInfo.getList(), baseQuery.getPage(), pageSize, pages);
        return aisOperRegDtoPageList;
    }

    public PageList<FinIpbItemlistDto> getFinIpbItemlistThree(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getPage(), baseQuery.getPageSize());
        List<FinIpbItemlistDto> list = finIpbItemlistDtoMapper.loadFinIpbItemlistThree(baseQuery.getStartTime(), baseQuery.getEndTime(), PrimaryCareThree);
        PageInfo<FinIpbItemlistDto> pageInfo = new PageInfo<>(list);
        Integer pageSize = NumberUtils.drawSurplus(pageInfo.getTotal(), baseQuery.getPageSize());
        Integer pages = NumberUtils.totalPages(pageInfo.getTotal(), baseQuery.getPageSize());
        PageList<FinIpbItemlistDto> aisOperRegDtoPageList = new PageList<>(pageInfo.getTotal(), pageInfo.getList(), baseQuery.getPage(), pageSize, pages);
        return aisOperRegDtoPageList;
    }


    public List<FinIpbItemlistVo> getListData(List<FinIpbItemlistVo> list) {
        Map<String, List<FinIpbItemlistVo>> collect = list.stream().collect(Collectors.groupingBy(
                FinIpbItemlistVo::getSimpleName
        ));
        for (FinIpbItemlistVo finIpbItemlistvo : list) {
            String name = finIpbItemlistvo.getSimpleName();
            List<FinIpbItemlistVo> list1 = collect.get(name);
            Set<String> strings = collect.keySet();
            for (String string : strings) {
                if (string == name) {
                    List<FinIpbItemlistVo> primaryCareOneList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareOne)).collect(Collectors.toList());
                    List<FinIpbItemlistVo> primaryCareTwoList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareTwo)).collect(Collectors.toList());
                    List<FinIpbItemlistVo> primaryCareThreeList = list.stream().filter(m ->
                            m.getItemName().equals(PrimaryCareThree)).collect(Collectors.toList());
                    finIpbItemlistvo.setPrimaryCareOne(primaryCareOneList.size());
                    finIpbItemlistvo.setPrimaryCareTwo(primaryCareTwoList.size());
                    finIpbItemlistvo.setPrimaryCareThree(primaryCareThreeList.size());
                }
            }
        }
        List<FinIpbItemlistVo> collects = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
                Comparator.comparing(FinIpbItemlistVo::getSimpleName)
        )), ArrayList::new));
        return collects;
    }


}
